package com.keyancompany.zhongbaopingtai.activity;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import com.keyancompany.zhongbaopingtai.Constants;
import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.adapter.IFragmentPagerAdapter;
import com.keyancompany.zhongbaopingtai.fragment.WeeklyFragment;
import com.keyancompany.zhongbaopingtai.utils.IntentUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.BindString;

public class WeeklyActivity extends BaseActivity {

    @BindString(R.string.weekly_text)
    String weeklyTitle;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.tabLayout)
    TabLayout tabLayout;
    @Bind(R.id.complaint_viewpager)
    ViewPager complaintViewpager;

    private String teamCode;

    @Override
    protected int getContentViewId() {
        return R.layout.layout_tab_viewpager;
    }

    @Override
    protected int getMenuId() {
        return R.menu.weekly_publish_menu;
    }

    @Override
    protected void initToolBar() {
        initToolBar(toolbar, weeklyTitle);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.action_publish_weekly) {
            IntentUtils.startActivity(mContext, CreateWeeklyActivity.class,Constants.TEAM_CODE,teamCode);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    @Override
    protected void setUpViews() {
        initMaliteView();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }


//    public void initSingleView() {
//        tabLayout.setVisibility(View.GONE);
//        List<Fragment> fragmentList = new ArrayList<>();
//        WeeklyFragment weeklyFragment = WeeklyFragment.newInstance(1, 1);
//        fragmentList.add(weeklyFragment);
//        complaintViewpager.setAdapter(new IFragmentPagerAdapter(getSupportFragmentManager(), fragmentList));
//    }

    public void initMaliteView() {
        tabLayout.addTab(tabLayout.newTab());
        tabLayout.addTab(tabLayout.newTab());
        teamCode = getIntent().getStringExtra(Constants.TEAM_CODE);
        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(WeeklyFragment.newInstance(teamCode, 0));
        WeeklyFragment weeklyFragment = WeeklyFragment.newInstance(teamCode, 1);
        fragmentList.add(weeklyFragment);
        IFragmentPagerAdapter pagerAdapter = new IFragmentPagerAdapter(getSupportFragmentManager(), fragmentList);
        pagerAdapter.setTitles(getResources().getStringArray(R.array.weekly_tab_titles));
        complaintViewpager.setAdapter(pagerAdapter);
        tabLayout.setupWithViewPager(complaintViewpager);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
    }

}
